//
// Created by Tony on 2024/6/13.
//

#ifndef RUNTIME_BYTE_CODE_READER_H
#define RUNTIME_BYTE_CODE_READER_H

#include "rt_code/Code.h"
#include <cstdint>
#include <memory>

namespace Runtime {

using Common::OpCode;
using std::shared_ptr;

class ByteCodeReader {
    shared_ptr<RtCode::Code> mCode;
    uint32_t mPC;

public:
    ByteCodeReader(const shared_ptr<RtCode::Code>& code, uint32_t pc);
    ByteCodeReader();

    void reset(const shared_ptr<RtCode::Code>& code, uint32_t pc);

    OpCode readOpCode();
    uint16_t readUint16();
    int16_t readInt16();

    uint32_t getNextPC() const;
};

} // namespace Runtime

#endif // RUNTIME_BYTE_CODE_READER_H
